const Koa = require("koa");
const fs = require("fs");

const serve = require("koa-static");

const app = new Koa();

// 前端用 history
// 一定要配置一下后端服务
app.use(serve(__dirname + "/static"));

app.use((ctx) => {
  console.log("1111");
  // 一直返回 index.html
  const indexString = fs.readFileSync("./static/index.html");

  ctx.set("content-type", "text/html");
  //   ctx.body = fs.readFileSync("./static/index.html");
  ctx.body = indexString.toString();
});

app.listen(8080, () => {
  console.log("open server localhost:8080");
});
